using System;
using System.Xml;

using DesignByContract;

using Outcoding.GraphGenerator.Entities;

namespace Outcoding.GraphGenerator.XmlBuilders {
    public class XmlBuilderFactory {
        private static XmlBuilderFactory mInstance = null;

        public static XmlBuilderFactory Instance{
            get {
                if(mInstance == null)
                    mInstance = new XmlBuilderFactory();
                return mInstance;
            }
        }

        private XmlBuilderFactory() { 
        }

        public IXmlBuilder GetXmlBuilder(Entities.XmlTagNames tag, XmlNode node) {
            IXmlBuilder xmlBuilder = null;
            switch(tag){
                case XmlTagNames.axes:
                    xmlBuilder = new AxesXmlBuilder(node);
                    break;
                case XmlTagNames.categoryaxis:
                    xmlBuilder = new CategoryAxisXmlBuilder(node);
                    break;
                case XmlTagNames.datatable:
                    xmlBuilder = new DatatableXmlBuilder(node);
                    break;
                case XmlTagNames.graph:
                    xmlBuilder = new GraphXmlBuilder(node);
                    break;
                case XmlTagNames.industry:
                    xmlBuilder = new IndustryXmlBuilder(node);
                    break;
                case XmlTagNames.label:
                    xmlBuilder = new LabelXmlBuilder(node);
                    break;
                case XmlTagNames.labelcollection:
                    xmlBuilder = new LabelXmlBuilder(node);
                    break;
                case XmlTagNames.legend:
                    xmlBuilder = new LegendXmlBuilder(node);
                    break;
                case XmlTagNames.maxvalue:
                    xmlBuilder = new IAxisValueXmlBuilder(node);
                    break;
                case XmlTagNames.minvalue:
                    xmlBuilder = new IAxisValueXmlBuilder(node);
                    break;
                case XmlTagNames.point:
                    xmlBuilder = new PointXmlBuilder(node);
                    break;
                case XmlTagNames.pointcollection:
                    xmlBuilder = new PointCollectionXmlBuilder(node);
                    break;
                case XmlTagNames.presentation:
                    xmlBuilder = new PresentationXmlBuilder(node);
                    break;
                case XmlTagNames.scale:
                    xmlBuilder = new IAxisValueXmlBuilder(node);
                    break;
                case XmlTagNames.series:
                    xmlBuilder = new SeriesAxisXmlBuilder(node);
                    break;
                case XmlTagNames.seriesaxis:
                    xmlBuilder = new SeriesAxisXmlBuilder(node);
                    break;
                case XmlTagNames.seriescollection:
                    xmlBuilder = new SeriesCollectionXmlBuilder(node);
                    break;
                case XmlTagNames.shape:
                    xmlBuilder = new ShapeXmlBuilder(node);
                    break;
                case XmlTagNames.slide:
                    xmlBuilder = new SlideXmlBuilder(node);
                    break;
                case XmlTagNames.slidecollection:
                    xmlBuilder = new SlideCollectionXmlBuilder(node);
                    break;
                case XmlTagNames.valueaxis:
                    xmlBuilder = new ValueAxisXmlBuilder(node);
                    break;
                case XmlTagNames.unknown:
                    xmlBuilder = null;
                    break;
            }

            return xmlBuilder;
        }
    }
}